package test.date;

import org.apache.commons.lang3.time.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;

public class DateTest1 {
    public static void main(String[] args) {
        String o = (String) null;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(format.format(new Date()));
        System.out.println(format.format(new Date()));
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        System.out.println(c.get(Calendar.MILLISECOND));

        System.out.println(DateUtils.setDays(DateUtils.setMonths(new Date(), 9),1));

        System.out.println(DateUtils.truncate(new Date(), Calendar.MONDAY));

        Iterator<Calendar> iterator = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_SUNDAY);
        Calendar next = iterator.next();
        printFormatDate(new Date(next.getTimeInMillis()));

    }

    public static void printFormatDate(Date d) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(df.format(d));
    }
}
